package com.romain.risotto.message;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.andengine.extension.multiplayer.protocol.adt.message.client.IClientMessage;
import org.andengine.extension.multiplayer.protocol.adt.message.server.ServerMessage;

public class CreatePlayerMessage extends ServerMessage implements IClientMessage {

	public short idPlayer;
	public int x;
	public int y;
	public float direction;

	public CreatePlayerMessage() {
	}
	public CreatePlayerMessage(short idPlayer,int px, int py, float pdir) {
		super();
		this.idPlayer = idPlayer;
		x= px;
		y = py;
		direction = pdir;
	}

	@Override
	public short getFlag() {
		return MessageFlags.FLAG_MESSAGE_NEW_PLAYER;
	}

	@Override
	protected void onReadTransmissionData(DataInputStream pDataInputStream)
			throws IOException {
		this.idPlayer = pDataInputStream.readShort();
		this.x = pDataInputStream.readInt();
		this.y = pDataInputStream.readInt();
		this.direction = pDataInputStream.readFloat();
		
	}

	@Override
	protected void onWriteTransmissionData(DataOutputStream pDataOutputStream)
			throws IOException {
		pDataOutputStream.writeShort(this.idPlayer);
		pDataOutputStream.writeInt(x);
		pDataOutputStream.writeInt(y);
		pDataOutputStream.writeFloat(this.direction);
		
	}

}
